import { Injectable } from '@angular/core';
import {Observable} from "rxjs";
import {HttpClient, HttpHeaders} from "@angular/common/http";

@Injectable({
  providedIn: 'root'
})
export class UserService {

  constructor(
    private http:HttpClient
  ) { }

  loginUrl="http://localhost:3000/user/login"
  infoUrl="http://localhost:3000/user/exist"
  registerUrl="http://localhost:3000/user/register"

  httpOptions={
    headers:new HttpHeaders({
      'Content-Type':'application/json',
      'Authorization': 'my-auth-token'
    })
  }

  loginService(object:object):Observable<any>{
    return this.http.post(this.loginUrl,object,this.httpOptions)
  }

  getInfoService(data:string):Observable<any>{
    let httpOptions={
      headers:new HttpHeaders({
        'Content-Type':'application/json',
      })
    }
    return this.http.post(this.infoUrl,httpOptions)
  }

  register(data:any){
    return this.http.post(this.registerUrl,data,this.httpOptions)
  }
}
